home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 06 - 1990 / 06.09 Sep 90 / Debugger DA / DebuggerDA.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-11-26  |  59.1 KB  |  2,182 lines  |  [TEXT/KAHL]

  1. /********************************************************************/
  2. /*                                                                    */
  3. /*    Source  - DebuggerDA.c                                            */
  4. /*    Author  - Alexander S. Colwell, Copyright (C) 1988, 1989        */
  5. /*                                                                    */
  6. /*    Purpose - This is the "Debugger" desk accessory to simplify        */
  7. /*              debugging code resources, DA's or applications that    */
  8. /*              does not have a debugging output window. It requires     */
  9. /*              System 4.1 or greater version.                        */
  10. /*                                                                    */
  11. /*    Routine - Main                 : Main entry point module.        */
  12. /*              DoOpen               : Open the DA and initialized.    */
  13. /*            DoClose              : Close the DA and wrap it up.    */
  14. /*              DoControl           : Process DA control commands.    */
  15. /*              DoEvent             : Process DA event.                */
  16. /*              DoUpdate              : Update window.                    */
  17. /*              DoMouse              : Process mouse-down.                */
  18. /*              DoActivate          : Activate/Deactivate window.        */
  19. /*              DoActivateScrollBars: Activate the scroll bars        */
  20. /*              DoDeActivateScrollBars:Deactivate the scroll bars.    */
  21. /*              DoIdle              : Do idle processing.                */
  22. /*              DoKey                  : Process key inputs.                */
  23. /*              DoMenu              : Do menu commands.                */
  24. /*              DoContent              : Process mouse down inside window*/
  25. /*              DoCopy              : Copy the selected text.            */
  26. /*              DoClear              : Clear the display.                */
  27. /*              DoQuit              : Quit the DA, found a problem.    */
  28. /*              DoInfo              : Show information about this DA.    */
  29. /*              DoStartStopOutput   : Start/Stop output display.        */
  30. /*              DoError              : Show error message to user.        */
  31. /*              DoTextClick          : Do text clicking.                */
  32. /*              DoScrollBar          : Do scroll bar.                    */
  33. /*              DoTextScroll          : Do text scrolling action.        */
  34. /*              DoClickScroll          : Do click scrolling.                */
  35. /*              DoHighLite          : Do highliting.                    */
  36. /*              DoNewLineToReturn   : Convert NEW-LINE to RETURN chars*/
  37. /*              DoPrintLine          : Print line.                        */
  38. /*              DoDbgPrintSetup      : Setup debugging print output.    */
  39. /*              DoDbgPrint          : Do debugging print output.        */
  40. /*              DoPrintDump          : Dump stuff.                        */
  41. /*              DoRestoreClippings  : Restore text view clippings.    */
  42. /*              DoAdjustScrollBar      : Adjust the scroll bar's thumb.    */
  43. /*              DoSetupView          : Setup the view.                    */
  44. /*              DoAdjustView          : Adjust the view.                */
  45. /*              DoResizeScrollBar   : Resize the scroll bar.            */
  46. /*              DoDlgCenter          : Center dialog window.            */
  47. /*              DoItemIdx              : Find item index str comparsion.    */
  48. /*              GetResourceID       : Get DA resource ID number.        */
  49. /*                                                                    */
  50. /*    Revisions - None.                                                */
  51. /*                                                                    */
  52. /********************************************************************/
  53.  
  54. #include "Debugger.h"                /* DA Debugger defs                */
  55. #include <Color.h>                    /* Color Manager defs            */
  56. #include <CType.h>                    /* C Type defs                    */
  57. #include <StdArg.h>                    /* Standard Argument defs        */
  58. #include <SetUpA4.h>                /* Desk Accessory defs            */
  59. #include <PE.h>                        /* Program Edit defs            */
  60.  
  61.                                     /* Misc definitions                */
  62. #define    NIL        (0L)                /* NIL pointer                    */
  63. #define    abs(a)    (a<0?-a:a)            /* Absolute macro function        */
  64. #define    min(a,b) (a<b?a:b)            /* Minumim macro function        */
  65. #define    max(a,b) (a<b?b:a)            /* Maximum macro function        */
  66.  
  67.                                     /* Trap definitions                */
  68. #define    SysEnvironsTrap    0xa090        /* System Enviorment trap        */
  69. #define    UnknownTrap        0xa89f        /* Unknown trap instruction        */
  70.  
  71.                                     /* Limit definitions            */
  72. #define    maxColumns        132            /* Maximum # of columns            */
  73.  
  74.                                     /* Resource ID #'s                */
  75. #define    windID            0            /* Window ID #                    */
  76. #define    infoID            0            /* Info dialog ID #                */
  77. #define    errorID            1            /* Error dialog ID #            */
  78. #define    strID            0            /* String STR ID #                */
  79. #define    errID            1            /* Error STR ID #                */
  80. #define    optionsID        0            /* Options ID #                    */
  81. #define    debuggerID        0            /* Debugger ID #                */
  82.  
  83. typedef enum {                        /* Menu commands                */
  84.     Info = 1,                        /* On-line information            */
  85.     NullItem2,
  86.     StartOutput,                    /* Start/Stop output display    */
  87.     Quit                            /* Quit from DA                    */
  88.     } MENU;
  89.     
  90. typedef enum {                        /* String ID #'s                */
  91.     itmStartOutput = 1,                /* "Start Output" item            */
  92.     itmStopOutput,                    /* "Stop Output" item            */
  93.     bufTableOvrFlw,                    /* Table overflow                */
  94.     bufDataOvrFlw,                    /* Data buffer overflow            */
  95.     bufBufOvrFlw                    /* Buffer size overflow            */
  96.     } STRID;
  97.                                     /* Resource types                */
  98. #define    optionType        'Opts'        /* Option definitions type        */
  99.  
  100. typedef enum {                        /* Error messages                */
  101.     errFailOpenDA = 1,                /* Fail to open DA                */
  102.     errNoGlobals,                    /* Fail to allocate globals        */
  103.     errLowMemory,                    /* Low memory error                */
  104.     errOldSystem,                    /* Old System file < 4.1 version*/
  105.     errLisaClone,                    /* Lisa clone Macintosh            */
  106.     errOriginalMac                    /* Original 128/512 Mac!        */
  107.     } ERROR;
  108.     
  109. typedef struct {                    /* Options definitions            */
  110.     short    maxTextSize;            /* Maximum text size            */
  111.     short    fontFamily;                /* Font ID family                */
  112.     short    fontSize;                /* Font size                    */
  113.     short    spacesPerTab;            /* # of spaces per tab            */
  114.     long    bufTableSize;            /* Buffer table size            */
  115.     long    bufDataSize;            /* Buffer data size                */
  116.     } OPT;
  117. typedef OPT        *OPTPTR;
  118. typedef OPTPTR    *OPTHDL;
  119.  
  120. short             alreadyOpen = FALSE;/* 1 -> DA is already open      */
  121. SysEnvRec        sysEnv;                /* System enviroment            */
  122. DCtlPtr         dce;                /* Device control entry          */
  123. WindowPtr         wp = NIL;            /* My window pointer             */
  124. Rect            originalRect;        /* Original window rect area    */
  125. PEHandle        peHdl = NIL;        /* PE handle                    */
  126. short            active = FALSE;        /* Active flag indicator        */
  127. ControlHandle    hScrollBar = NIL;    /* Horz scroll bar control hdl    */
  128. ControlHandle    vScrollBar = NIL;    /* Horz scroll bar control hdl    */
  129. DBGHDL            dbgHdl = NIL;        /* Debugger handle                */
  130. OPTHDL            optHdl = NIL;        /* Options handle                */
  131. short            cursorMode = FALSE;    /* Current I-beam cursor mode    */
  132. MenuHandle        menu = NIL;            /* Menu handle                    */
  133. short            menuID = 0;            /* Menu ID #                    */
  134. long            **bufTable = NIL;    /* Buffer index table handle    */
  135. char            **bufData = NIL;    /* Buffer data handle            */
  136. short            outputEnable = TRUE;/* Output stream enable flag    */
  137.  
  138. char            PrintOutputBuf[1024];/* Print output buffer            */
  139.  
  140. pascal void DoTextScroll();            /* Define forwared references    */
  141. pascal void    DoClickScroll();
  142. pascal void    DoHighLite();
  143. void        DoPrintChar();
  144.  
  145. DialogTHndl DoDlgCenter();
  146.  
  147. main(p,d,n)
  148.  
  149.     cntrlParam     *p;                    /* Parameter block              */
  150.     DCtlPtr     d;                    /* Device control entry          */
  151.     short         n;                    /* Entry point selector          */
  152.     
  153.     {
  154.  
  155.         WindowPtr    savePort;        /* Save current window port        */
  156.         short        saveResFile;    /* Save current resource file    */
  157.  
  158.         if (d->dCtlStorage == 0) {    /* Check if got the globals 1st!*/
  159.         
  160.             if (n == 0)    {            /* Check if requesting "Open"    */
  161.             
  162.                 DoError(errNoGlobals);/* Opps, fail to get globals    */
  163.                 
  164.                 CloseDriver(d->dCtlRefNum);/* Close the DA            */
  165.                 
  166.             }
  167.             
  168.         }
  169.         
  170.         else {                        /* Got the globals then continue*/
  171.         
  172.             RememberA4();            /* Remember A4 register            */
  173.             
  174.             GetPort(&savePort);        /* Get current window port        */
  175.             
  176.             if (wp)                    /* Check if window ptr valid    */
  177.                 SetPort(wp);        /* Set port to my window        */
  178.                 
  179.             dce = d;                /* Save DCE ptr into our globals*/
  180.             
  181.             dce->dCtlFlags &= ~dCtlEnable;/* Set it not to be re-entrant*/
  182.             
  183.             switch(n) {                /* Handle request:                 */
  184.             
  185.                 case 0:                /*      "Open"                    */
  186.                     DoOpen(); break;    
  187.                     
  188.                 case 2:                /*      "Control"                 */
  189.                     DoControl(p->csCode,p->csParam); break;    
  190.                     
  191.                 case 4:                /*      "Close"                       */
  192.                     DoClose(); break;
  193.                     
  194.             }
  195.             
  196.             dce->dCtlFlags |= dCtlEnable;/* Enable calls once more    */
  197.             
  198.             SetPort(savePort);        /* OK, let's restore it            */
  199.             
  200.         }
  201.         
  202.         return(0);                    /* Return default success          */
  203.         
  204.     }
  205.  
  206. DoOpen()
  207.  
  208.     {
  209.     
  210.           short            rom;        /* Working ROM id                */
  211.           short            machine;    /* Working Mac id                */
  212.         Rect            wRect;        /* Working window rect area        */
  213.         register PEPtr    pePtr;        /* Working edit pointer            */
  214.         DBGPTR            dbgPtr;        /* Working debugger pointer        */
  215.         register short    canDoIt;    /* Working can do it indicator    */
  216.         register short    errCode = errFailOpenDA;/* Working error code*/
  217.         Point            pt;            /* Working point                */
  218.         
  219.                                     /* Add neccesary driver flags    */
  220.         dce->dCtlFlags |= dNeedLock|dNeedGoodBye;
  221.         
  222.         if (wp)                        /* Check if there a window        */
  223.             if (wp != FrontWindow())/* Check if not in the front    */
  224.                 SelectWindow(wp);    /* Bring our window front         */
  225.             
  226.         if (!alreadyOpen) {            /* Check if require inits        */
  227.             
  228.               Environs(&rom,&machine);/* Get Mac's evniroment            */
  229.       
  230.               if (machine == macXLMachine) {/* Check if Lisa clone    */
  231.                   canDoIt = FALSE;    /* It's a Lisa computer!        */
  232.                   errCode = errLisaClone;/* Set error message            */
  233.               }
  234.              
  235.               else if (rom >= 0x0078) /* It's Mac II                    */
  236.                  canDoIt = TRUE;        /* It's Mac II computer            */
  237.           
  238.               else if (rom >= 0x0076)    /* It's Mac SE                    */
  239.                  canDoIt = TRUE;        /* It's Mac SE computer            */
  240.              
  241.               else if (rom >= 0x0075) {/* it's 128K rom                */
  242.           
  243.                                       /* Check if Mac 512KE computer    */
  244.                  if (MemTop > (char *)(1024L * 512L))
  245.                     canDoIt = TRUE;    /* It's Mac 512K Enhanced        */
  246.                 
  247.                  else
  248.                     canDoIt = TRUE;    /* Its Mac Plus computer        */
  249.                 
  250.               }
  251.              
  252.               else  if (rom >= 0x0069){/* It's 64K rom, it's old one    */
  253.                  canDoIt = FALSE;    /* It's original Mac!            */
  254.                  errCode = errOriginalMac;/* Set error message        */
  255.             }
  256.             
  257.             if (canDoIt) {            /* OK, we can do it!            */
  258.             
  259.                                       /* Check if SysEnvirons valid    */
  260.                  if ((long)NGetTrapAddress(SysEnvironsTrap,OSTrap) != 
  261.                      (long)NGetTrapAddress(UnknownTrap,ToolTrap)) {
  262.                      
  263.                     SysEnvirons(1,&sysEnv);/* Get system enviroment    */
  264.                     
  265.                                     /* Check if has latest version    */
  266.                     if (sysEnv.systemVersion >= 0x0410) {
  267.                     
  268.                         wp = GetNewWindow(GetResourceID(windID),NIL,-1L);
  269.                                 
  270.                         if (wp) {    /* Check if got the window        */
  271.                                 
  272.                             ShowWindow(wp);/* OK, let's show it        */
  273.                             
  274.                             SetPort(wp);/* Set port to our window    */
  275.                             
  276.                                     /* Set open DA indicator        */
  277.                             alreadyOpen = TRUE;
  278.                             
  279.                                     /* Save window association        */
  280.                             ((WindowPeek)wp)->windowKind = dce->dCtlRefNum;
  281.                             
  282.                                     /* Tell device where I am        */
  283.                             dce->dCtlWindow = wp;
  284.                             
  285.                                     /* Save original rect area        */
  286.                             originalRect = wp->portRect;
  287.                             LocalToGlobal(&originalRect.top);
  288.                             LocalToGlobal(&originalRect.bottom);
  289.                             
  290.                                        /* Set horizontal rect area        */
  291.                             wRect.left = wp->portRect.left - 1;
  292.                             wRect.top = wp->portRect.bottom - 15;
  293.                             wRect.right = wp->portRect.right - 14;
  294.                             wRect.bottom = wp->portRect.bottom + 1;
  295.               
  296.                                     /* Check if create scroll bar    */
  297.                             hScrollBar = NewControl(wp,&wRect,"",FALSE,
  298.                                                     0,0,0,scrollBarProc,0L);
  299.                                 
  300.                                        /* Set vertical rect area        */
  301.                             wRect.left = wp->portRect.right - 15;
  302.                             wRect.top = wp->portRect.top - 1;
  303.                             wRect.right = wp->portRect.right + 1;
  304.                             wRect.bottom = wp->portRect.bottom - 14;
  305.               
  306.                                     /* Check if create scroll bar    */
  307.                             vScrollBar = NewControl(wp,&wRect,"",FALSE,
  308.                                                     0,0,0,scrollBarProc,0L);
  309.                                 
  310.                                     /* Get options definitions        */
  311.                             optHdl = (OPTHDL)(GetResource(optionType,
  312.                                                  GetResourceID(optionsID)));
  313.                                                      
  314.                                     /* Get debugger definitions        */
  315.                             dbgHdl = (DBGHDL)(GetResource(debuggerType,
  316.                                                  GetResourceID(debuggerID)));
  317.                                                  
  318.                             TextFace(0);/* Set to "Plain" style font*/
  319.                             
  320.                             if (optHdl) {/* Check if got option hdl*/
  321.                                 TextSize((*optHdl)->fontSize);
  322.                                 TextFont((*optHdl)->fontFamily);
  323.                              }
  324.                              
  325.                              else {    /* Nope, default to standard    */
  326.                                 TextSize(9);
  327.                                 TextFont(monaco);
  328.                              }
  329.                              
  330.                                      /* Set edit view rect area        */
  331.                             wRect.left = wp->portRect.left;
  332.                             wRect.top = wp->portRect.top + 5;
  333.                             wRect.right = wp->portRect.right - 15;
  334.                             wRect.bottom = wp->portRect.bottom - 15;
  335.  
  336.                                      /* Check if get edit handle        */
  337.                              if (peHdl = PENew(&wRect)) {
  338.                              
  339.                                  pePtr = *peHdl;/* Set edit pointer    */
  340.                                  
  341.                                        /* Set auto scroll hook            */
  342.                                    pePtr->clikLoop = (ProcPtr)DoClickScroll;
  343.                    
  344.                                        /*Check if has color monitor    */
  345.                                 if (sysEnv.hasColorQD)
  346.                                     pePtr->highHook = (ProcPtr)DoHighLite;
  347.                                
  348.                                        /* Set horizontal offset        */
  349.                                    pePtr->viewOrgH = -5;
  350.                                
  351.                                        /* Set vertical offset            */
  352.                                    pePtr->viewOrgV = 0;
  353.                
  354.                                        /* Set the # of spaces per tab    */
  355.                                    (*peHdl)->tabWidth = CharWidth(' ') * 
  356.                                        (*optHdl)->spacesPerTab;
  357.                                        
  358.                                        /* Restore text view clippings    */
  359.                                    DoRestoreClippings();
  360.                                    
  361.                                }
  362.                                
  363.                                        /* Check if got the menu handle    */
  364.                                if (menu = GetMenu(menuID = GetResourceID(menuID))) {
  365.                                
  366.                                        /* Reset the default menu ID #    */
  367.                                 (**menu).menuID = menuID;
  368.                                 
  369.                                     /* Init menu ID #                */
  370.                                 dce->dCtlMenu = menuID;
  371.                                 
  372.                                 if (!dbgHdl)/* Check if fail to get it*/
  373.                                     DisableItem(menu,StartOutput);
  374.                                     
  375.                               }
  376.                               
  377.                               else    /* Fail to get menu handle        */
  378.                                   menuID = 0;/* Reset menu ID #        */
  379.                                   
  380.                               if (optHdl) {/* Check if got option info*/
  381.                               
  382.                                       /* Allocate buffer table        */
  383.                                   bufTable = (long **)(NewHandle(
  384.                                       (long)((*optHdl)->bufTableSize) *
  385.                                       (long)(sizeof(long))));
  386.                   
  387.                                       /* Allocate buffer data        */
  388.                                   bufData = NewHandle(
  389.                                       (long)((*optHdl)->bufDataSize) *
  390.                                       (long)(sizeof(char)));
  391.                   
  392.                               }
  393.                                     /* Check if memory runing low    */
  394.                             if (!hScrollBar || !vScrollBar || 
  395.                                 !peHdl || !menu || !optHdl || !dbgHdl || 
  396.                                 !bufTable || !bufData)
  397.                                 DoError(errLowMemory);
  398.                                 
  399.                                     /* Check if got the resources    */
  400.                             if (dbgHdl) {
  401.                             
  402.                                     /* Make sure it correct size    */
  403.                                 SetHandleSize(dbgHdl,
  404.                                     (long)(sizeof(DBGINTERFACE)));
  405.                                     
  406.                                 dbgPtr = *dbgHdl;/* Set debugger ptr*/
  407.                                 
  408.                                     /* Init debugger buffer stuff    */
  409.                                 dbgPtr->bufError = dbgNoOvrFlw;
  410.                                 dbgPtr->bufTableIdx = 0;
  411.                                 dbgPtr->bufNextIdx = 0;
  412.                                 dbgPtr->bufDataIdx = 0;
  413.                                 dbgPtr->bufTableSize = 0L;
  414.                                 dbgPtr->bufTable = NIL;
  415.                                 dbgPtr->bufData = NIL;
  416.                                 dbgPtr->bufDataSize = 0L;
  417.                                 dbgPtr->daRefNbr = 0;
  418.                                 
  419.                                     /* Check if other tables valid  */
  420.                                 if (optHdl && bufTable && bufData) {
  421.                                     dbgPtr->bufTableSize = 
  422.                                         (*optHdl)->bufTableSize;
  423.                                     dbgPtr->bufTable = bufTable;
  424.                                     dbgPtr->bufData = bufData;
  425.                                     dbgPtr->bufDataSize = 
  426.                                     (*optHdl)->bufDataSize;
  427.                                     dbgPtr->daRefNbr = dce->dCtlRefNum;
  428.                                 }
  429.                                 
  430.                                 ChangedResource(dbgHdl);/* Update it*/
  431.                                 WriteResource(dbgHdl);
  432.                                 
  433.                             }
  434.                             
  435.                         }
  436.                         
  437.                     }
  438.                     
  439.                     else            /* Require newer system            */
  440.                         errCode = errOldSystem;
  441.                     
  442.                 }
  443.                 
  444.                 else                /* Require new system            */
  445.                     errCode = errOldSystem;
  446.                 
  447.             }
  448.             
  449.             if (!wp) {                /* Check if fail to open        */
  450.             
  451.                 DoError(errCode);    /* Fail to open DA                */
  452.                 
  453.                 DoQuit();            /* Let's get out now!            */
  454.                 
  455.             }
  456.             
  457.         }
  458.         
  459.     }
  460.  
  461. DoClose()
  462.  
  463.     {
  464.     
  465.         register Handle    hdl;        /* Working handle                */
  466.         Rect            curRect;    /* Working current rect area    */
  467.         register Rect    **wRect;    /* Working window rect area        */
  468.         
  469.         if (dbgHdl) {                /* Check if have the interface    */
  470.         
  471.             (*dbgHdl)->daRefNbr = 0;/* OK, let's clear these        */
  472.             (*dbgHdl)->bufTable = NIL;
  473.             (*dbgHdl)->bufData = NIL;
  474.                 
  475.             ChangedResource(dbgHdl);/* Update the resource, too        */
  476.             WriteResource(dbgHdl);
  477.             
  478.             dbgHdl = NIL;            /* Clear the handle, but don't*/
  479.                                     /* release it since other DA's    */
  480.                                     /* and etc will be using it, too*/
  481.                             
  482.         }
  483.         
  484.         if (bufTable)                /* Check if it's valid            */
  485.             DisposHandle(bufTable);    /* Release it to memory manager    */
  486.         bufTable = NIL;                /* Invalidate it                */
  487.         
  488.         if (bufData)                /* Check if it's valid            */
  489.             DisposHandle(bufData);    /* Release it to memory manager    */
  490.         bufData = NIL;                /* Invalidate it                */
  491.         
  492.         if (optHdl)                    /* Check if have option handle    */
  493.             ReleaseResource(optHdl);/* Release it                    */
  494.         optHdl = NIL;                /* Invalidate it too            */
  495.         
  496.         if (menu) {                    /* Check if have the menu handle*/
  497.         
  498.             DeleteMenu(menuID);        /* Delete menu from menu bar    */
  499.             DrawMenuBar();
  500.             
  501.             DisposeMenu(menu);        /* Release menu handle            */
  502.             
  503.             menu = NIL;                /* Invalidate the menu handle    */
  504.  
  505.             dce->dCtlMenu = 0;        /* Clear-out menu ID #            */
  506.             
  507.         }
  508.         
  509.         if (peHdl) {                /* Check if edit handle is valid*/
  510.         
  511.             PEDispose(peHdl);        /* Release it now                */
  512.             
  513.             peHdl = NIL;            /* Invalidate the edit handle    */
  514.             
  515.         }
  516.         
  517.         if (wp) {                    /* Check if window ptr valid    */
  518.         
  519.             curRect = wp->portRect;    /* Translate to global coordinates*/
  520.             LocalToGlobal(&curRect.top);
  521.             LocalToGlobal(&curRect.bottom);
  522.             
  523.             DisposeWindow(wp);        /* Delete the window now        */
  524.                 
  525.             wp = NIL;                /* Reset it now                    */
  526.  
  527.                                     /* Check if window has changed    */
  528.             if (!EqualRect(&curRect,&originalRect)) {
  529.         
  530.                                       /* Check if got the window handle*/
  531.                   if (wRect = ((Rect **)GetResource('WIND',
  532.                                                     GetResourceID(windID)))) {
  533.                   
  534.                       **wRect = curRect;/* Save new current location    */
  535.                       
  536.                       ChangedResource(wRect);/* Mark it changed        */
  537.                       
  538.                       WriteResource(wRect);/* Write resource now        */
  539.                       
  540.                   }
  541.               
  542.               }
  543.               
  544.         }
  545.         
  546.                                     /* Get the 'STR#' resource        */
  547.         if (hdl = GetResource('STR#',GetResourceID(strID)))
  548.             ReleaseResource(hdl);    /* OK, let's release it now        */
  549.         if (hdl = GetResource('STR#',GetResourceID(errID)))
  550.             ReleaseResource(hdl);    /* OK, let's release it now        */
  551.             
  552.         InitCursor();                /* Restore to arrow cursor        */
  553.         
  554.         alreadyOpen = FALSE;        /* Reset it (really doesn't matter)*/
  555.         
  556.     }
  557.  
  558. DoControl(code,parm)
  559.  
  560.     short code;                        /* Control command code            */
  561.     short *parm;                    /* "csParam" list pointer        */
  562.     
  563.     {
  564.     
  565.         switch(code) {                /* Handle request:                */
  566.         
  567.             case accEvent:             /*        "Event"                    */
  568.                 DoEvent(*((EventRecord **)parm)); break;
  569.                 
  570.             case accMenu:            /*         "Menu"                    */
  571.                 DoMenu(*(parm + 1)); break;
  572.                 
  573.             case accRun:            /*        "Run"                    */
  574.                 DoIdle(); break;
  575.                 
  576.             case accCopy:            /*         "Copy"                    */
  577.                 DoCopy(); break;
  578.  
  579.             case accClear:            /*         "Clear"                    */
  580.                 DoClear(); break;
  581.             
  582.             case goodBye:              /*         "GoodBye"                */
  583.                 DoClose(); break;
  584.                 
  585.             case accDbgPrint:        /*        "DbgPrint"                */
  586.                 DoDbgPrint(((long *)(parm))); break;
  587.  
  588.             case accDbgDump:        /*        "DbgDump"                */
  589.                 DoPrintDump(*((long *)(parm)),*(((long *)(parm))+1)); break;
  590.  
  591.         }
  592.         
  593.     }
  594.  
  595. DoEvent(e)
  596.  
  597.     register EventRecord *e;        /* Event Record pointer            */
  598.  
  599.     {
  600.     
  601.         switch(e->what) {            /* Handle request:                */
  602.         
  603.             case updateEvt:         /*        "Update"                */
  604.                 DoUpdate();    break;
  605.                 
  606.             case mouseDown:            /*         "Mouse Down"            */
  607.                 DoMouse(e->where,e->modifiers); break;
  608.                 
  609.             case activateEvt:         /*         "Activate"                */
  610.                 DoActivate((Boolean)(e->modifiers & activeFlag)); break;
  611.                 
  612.             case keyDown:             /*        "Key Down"                */
  613.             case autoKey:            /*        "Auto-Key Down"            */
  614.             
  615.                                     /* Handle the input key            */
  616.                 DoKey((char)(e->message & charCodeMask),
  617.                       (char)((e->message & keyCodeMask) >> 8L),
  618.                       e->modifiers);
  619.                     
  620.         }
  621.         
  622.     }
  623.  
  624. DoUpdate()
  625.  
  626.     {
  627.     
  628.         Rect    wRect;                /* Working rect area            */
  629.         
  630.         BeginUpdate(wp);            /* Start update processing        */
  631.  
  632.         ClipRect(&wp->portRect);    /* Reset clipping for drawing    */
  633.         
  634.         EraseRect(&wp->portRect);    /* Erase part of screen first    */
  635.  
  636.         DrawGrowIcon(wp);            /* Draw the grow icon            */
  637.  
  638.         DrawControls(wp);            /* Draw the controls            */
  639.  
  640.         if (peHdl) {                /* Check if has edit handle        */
  641.         
  642.             DoRestoreClippings();    /* Restore text view clippgins    */
  643.                                    
  644.             PEUpdate(peHdl);        /* OK, let's update it            */
  645.             
  646.         }
  647.         
  648.         EndUpdate(wp);                /* Wrapup update processing        */
  649.  
  650.     }
  651.     
  652. DoMouse(p,modifiers)
  653.  
  654.     Point    p;                        /* Mouse point position            */
  655.     short    modifiers;                /* Mouse's modifiers            */
  656.  
  657.     {
  658.     
  659.         register long    i;            /* Working index                */
  660.         Rect            wRect;        /* Working window rect area        */
  661.         register long    wGrow;        /* Working grow size            */
  662.         ProcPtr         wDef;        /* Working window proc hdl        */
  663.     
  664.                                     /* Get window proc definition    */
  665.         wDef = (ProcPtr)*((WindowPeek)wp)->windowDefProc;
  666.  
  667.                                     /* Check if in "Content"        */
  668.         if (CallPascalL(8,wp,(int)wHit,p,wDef) == wInContent)
  669.             DoContent(p,modifiers);
  670.         
  671.                                     /* Check if in "Grow"            */
  672.         else if (CallPascalL(8,wp,(int)wHit,p,wDef) == wInGrow) {
  673.         
  674.             SetRect(&wRect,100,100,32767,32767);/* Define the limits*/
  675.             
  676.             wGrow = GrowWindow(wp,p,&wRect);/* OK, let's grow it now*/
  677.             
  678.             if (wGrow) {            /* Check if specified new size    */
  679.             
  680.                                     /* Reset new size                */
  681.                 SizeWindow(wp,LoWord(wGrow),HiWord(wGrow),TRUE);
  682.                 
  683.                 DoResizeScrollBar();/* Resize the scroll bar        */
  684.                 
  685.                 InvalRect(&wp->portRect);/* Invalidate everything    */
  686.                 
  687.                 DoAdjustScrollBar();/* Adjust scroll bar            */
  688.                 
  689.             }    
  690.             
  691.         }
  692.             
  693.                                     /* Check if in "Zoom In"        */
  694.         else if (CallPascalL(8,wp,(int)wHit,p,wDef) == wInZoomIn) {
  695.         
  696.             ZoomWindow(wp,inZoomIn,TRUE);/* Zoom it in                */
  697.         
  698.             DoResizeScrollBar();    /* Resize the scroll bar        */
  699.                 
  700.             DoAdjustScrollBar();    /* Adjust scroll bar            */
  701.                 
  702.         }
  703.                                     /* Check if in "Zoom Out"        */
  704.         else if (CallPascalL(8,wp,(int)wHit,p,wDef) == wInZoomOut) {
  705.         
  706.             ZoomWindow(wp,inZoomOut,TRUE);/* Zoom it out            */
  707.             
  708.             DoResizeScrollBar();    /* Resize the scroll bar        */
  709.                 
  710.             DoAdjustScrollBar();    /* Adjust scroll bar            */
  711.                 
  712.         }
  713.  
  714.     }
  715.     
  716. DoActivate(activate)
  717.  
  718.     short    activate;                /* Activate flag indicator        */
  719.  
  720.     {
  721.     
  722.         Rect    wRect;                /* Working window rect area        */
  723.         
  724.                                      /* Set vertical control area    */
  725.         wRect.left = wp->portRect.right - 14;
  726.         wRect.top = wp->portRect.top - 1;
  727.            wRect.right = wp->portRect.right + 1;
  728.            wRect.bottom = wp->portRect.bottom - 16;
  729.            
  730.            ClipRect(&wRect);            /* Reset clippings for a moment    */
  731.            
  732.         if (activate) {                /* Check if activating            */
  733.         
  734.             dce->dCtlFlags |= dNeedTime;/* Allow periodic invokation*/
  735.             
  736.             dce->dCtlDelay = 15;    /* Reset delay timer            */
  737.             
  738.             if (peHdl) {            /* Check if got the text        */
  739.         
  740.                 active = TRUE;        /* Activate text editing        */
  741.                 
  742.                 PEActivate(peHdl);    /* Activate the text            */
  743.         
  744.             }
  745.             
  746.             DoActivateScrollBars();    /* Activate scroll bars            */
  747.             
  748.             if (menu) {                /* Check if menu is valid        */
  749.             
  750.                 InsertMenu(menu,0);    /* Insert it into the menu bar    */
  751.                 DrawMenuBar();
  752.                 
  753.                 dce->dCtlMenu = menuID;/* Reset menu ID #            */
  754.  
  755.             }
  756.             
  757.         }
  758.         
  759.         else {                        /* Nope, deactivating            */
  760.         
  761.             if (dbgHdl) {            /* Check if it's valid            */
  762.             
  763.                                     /* Check if there buffer outputs*/ 
  764.                 if ((*dbgHdl)->bufTableIdx != (*dbgHdl)->bufNextIdx) {
  765.                 
  766.                                     /* Allow periodic invokation    */
  767.                     dce->dCtlFlags |= dNeedTime;
  768.                     
  769.                     dce->dCtlDelay = 15;/* Reset delay timer        */
  770.             
  771.                 }
  772.                 
  773.                 else                /* No, buffer outputs            */
  774.                     dce->dCtlFlags &= ~dNeedTime;/* Turn off perdiodic runs*/
  775.                 
  776.             }
  777.             
  778.             else                    /* Nope, use default settings    */
  779.                 dce->dCtlFlags &= ~dNeedTime;/* Turn off perdiodic runs*/
  780.             
  781.             active = FALSE;            /* Deactivate text editing        */
  782.             
  783.             if (peHdl)                 /* Check if got the text        */
  784.                 PEDeactivate(peHdl);/* Deactivate the text            */
  785.             
  786.             DoDeActivateScrollBars();/* Deactivate scroll bars        */
  787.             
  788.               InitCursor();            /* Restore to arrow cursor        */
  789.             
  790.             cursorMode = FALSE;        /* Reset cursor mode            */
  791.             
  792.             if (menu) {                /* Check if menu is valid        */
  793.             
  794.                 DeleteMenu(menuID);    /* Delete it from the menu bar    */
  795.                 DrawMenuBar();
  796.                 
  797.                 dce->dCtlMenu = 0;    /* Clear-out menu ID #            */
  798.                 
  799.             }
  800.             
  801.         }
  802.         
  803.     }
  804.     
  805. DoActivateScrollBars()
  806.  
  807.     {
  808.             
  809.         Rect    wRect;                /* Working rect area            */
  810.         
  811.         ClipRect(&wp->portRect);    /* Set clippings for moment        */
  812.         
  813.         if (hScrollBar)                /* Check if have horz scroll bar*/
  814.             ShowControl(hScrollBar);/* Show the scroll bar            */
  815.             
  816.         if (vScrollBar)                /* Check if have vert scroll bar*/
  817.             ShowControl(vScrollBar);/* Show the scroll bar            */
  818.         
  819.                                     /* Invalidate drag icon            */
  820.           wRect.top = wp->portRect.bottom - 14;
  821.           wRect.bottom = wp->portRect.bottom;
  822.           wRect.left = wp->portRect.right - 14;
  823.           wRect.right = wp->portRect.right;
  824.           InvalRect(&wRect);
  825.           
  826.         DoRestoreClippings();        /* Restore clippings            */
  827.                 
  828.     }
  829.     
  830. DoDeActivateScrollBars()
  831.  
  832.     {
  833.             
  834.         Rect    wRect;                /* Working rect area            */
  835.         
  836.         ClipRect(&wp->portRect);    /* Set clippings for moment        */
  837.         
  838.         if (hScrollBar)                /* Check if have horz scroll bar*/
  839.             HideControl(hScrollBar);/* Hide the scroll bar            */
  840.             
  841.         if (vScrollBar)                /* Check if have vert scroll bar*/
  842.             HideControl(vScrollBar);/* Hide the scroll bar            */
  843.         
  844.                                     /* Clear drag icon                */
  845.           wRect.top = wp->portRect.bottom - 14;
  846.           wRect.bottom = wp->portRect.bottom;
  847.           wRect.left = wp->portRect.right - 14;
  848.           wRect.right = wp->portRect.right;
  849.           EraseRect(&wRect);
  850.           
  851.           DoUpdate();                    /* Update the DA window            */
  852.           
  853.           DoRestoreClippings();        /* Restore clippings            */
  854.           
  855.     }    
  856.  
  857. DoIdle()
  858.  
  859.     {
  860.     
  861.         register short    id;            /* Working string ID #            */
  862.         register DBGPTR    dbgPtr;        /* Working debugger pointer        */
  863.         register char    *s,*f;        /* Working string pointers        */
  864.         Str255            wStr;        /* Working string                */
  865.         Point            p;            /* Working mouse location        */
  866.     
  867.         if (active) {                /* Check if it's activated        */
  868.         
  869.             GetMouse(&p);            /* Get mouse location            */
  870.             
  871.             if (peHdl)    {            /* Check if got the text        */
  872.             
  873.                 PEIdle(peHdl);        /* Do cursor blinking stuff        */
  874.             
  875.                                     /* Check if within view            */
  876.                 if (PtInRect(p,&(*peHdl)->viewRect)){
  877.                 
  878.                     if (!cursorMode) {/* Check if not showing I-beam*/
  879.                     
  880.                                     /* Reset to I-Beam cursor        */
  881.                         SetCursor(*GetCursor(iBeamCursor));
  882.                         
  883.                         cursorMode = TRUE;/* Reset cursor mode        */
  884.                     }
  885.                     
  886.                 }
  887.                 
  888.                 else {                /* Reset to standard arrow cursor*/
  889.                 
  890.                     if (cursorMode) {/* Check if using I-Beam cursor*/
  891.                     
  892.                           InitCursor();/* Restore to arrow cursor        */
  893.                       
  894.                           cursorMode = FALSE;/* Reset cursor mode        */
  895.                           
  896.                       }
  897.                       
  898.                 }
  899.             
  900.             }
  901.             
  902.         }
  903.         
  904.         if (dbgHdl) {                /* Check if debugger handle valid*/
  905.         
  906.             if ((*dbgHdl)->bufError) {/* Check for buffer overflow    */
  907.             
  908.                                     /* Get buffer error ID #        */
  909.                 switch((*dbgHdl)->bufError) {
  910.                     case bufTableOvrFlw:
  911.                         id = dbgTableOvrFlw; break;
  912.                         
  913.                     case bufDataOvrFlw:
  914.                         id = dbgDataOvrFlw; break;
  915.                         
  916.                     case bufBufOvrFlw:
  917.                         id = dbgBufOvrFlw;
  918.                         
  919.                 }
  920.                                     /* Let user know about it        */
  921.                 GetIndString(wStr,GetResourceID(strID),id);
  922.                 DoPrintLine("%p\n",wStr);
  923.                 
  924.                                     /* Reset flag indicator            */
  925.                 (*dbgHdl)->bufError = dbgNoOvrFlw;
  926.                 
  927.             }
  928.             
  929.             dbgPtr = *dbgHdl;        /* Set debugger pointer            */
  930.                 
  931.                                     /* Check if has changed            */
  932.             if (dbgPtr->bufTableIdx != dbgPtr->bufNextIdx) {
  933.                 
  934.                                     /* Bump to next index            */
  935.                 dbgPtr->bufTableIdx = (dbgPtr->bufTableIdx + 1L) %
  936.                     dbgPtr->bufTableSize;
  937.                 
  938.                 HLock(dbgPtr->bufData);/* Lock it down for output    */
  939.                 
  940.                                     /* Set switch code pointer        */
  941.                 s = &(*dbgPtr->bufData)[(*dbgPtr->bufTable)
  942.                     [dbgPtr->bufTableIdx]];
  943.         
  944.                 f = s + 2L;            /* Set format string address    */
  945.                 
  946.                 switch((unsigned char)(*s)){/* Process input command*/
  947.                 
  948.                     case accDbgPrint:/* Do LSC debugging line    */
  949.                         DoDbgPrintSetUp(f); break;
  950.                         
  951.                     case accDbgDump:/* Do debugging dump            */
  952.                         DoPrintDump(((long *)(f + sizeof(long))),
  953.                                     *((long *)(f)));
  954.                         
  955.                 }
  956.                 
  957.                 dbgPtr = *dbgHdl;    /* Reset debugger pointer        */
  958.                 
  959.                                     /* Check if it's finished        */
  960.                 if (dbgPtr->bufTableIdx == dbgPtr->bufNextIdx) {
  961.                 
  962.                     if (!active)    /* Check if not active            */
  963.                         dce->dCtlFlags &= ~dNeedTime;/* Turn it off    */
  964.                         
  965.                     else            /* Restore delay timer            */
  966.                         dce->dCtlDelay = 15;
  967.                         
  968.                 }
  969.  
  970.                 HUnlock(dbgPtr->bufData);/* OK, let's unlock it now    */
  971.                 
  972.             }
  973.             
  974.         }
  975.         
  976.     }
  977.     
  978. DoKey(c,code,modifiers)
  979.  
  980.     char    c;                        /* Input character                */
  981.     char    code;                    /* Input code                    */
  982.     short    modifiers;                /* Input modifiers                */
  983.     
  984.     {
  985.     
  986.         register short    i,j;        /* Working indexes                */
  987.         register short    adjustIt = TRUE;/* Working adjust cursor view*/
  988.         register short    item = 0;    /* Working item #                */
  989.         char            cmdChar[2];    /* Working command character    */
  990.         register ControlHandle ctrlHdl;/* Working control handle    */
  991.         static short cnt = 0;        /* Debugging counter            */
  992.         
  993.         if (active) {                /* Check if it's activated        */
  994.             
  995.             if (modifiers & cmdKey) {/* Check if key command        */
  996.             
  997.                 switch(c) {            /* Process key command            */
  998.                 
  999.                     case 'd':        /* "Debugging" command            */
  1000.                     case 'D':
  1001.                     
  1002.                         break;        /* Break early, skip debugging    */
  1003.                         
  1004.                         c = 0;        /* Reset it to bypass remainder    */
  1005.                         
  1006.                                     /* Output debugging stuff        */
  1007.                         for(i = 0; i < 30; i++) {
  1008.                             /*DbgPrint(dbgHdl,"Debugging - %d,%d, %s\n",
  1009.                                 i,cnt++,"Alex Colwell");*/
  1010.                             DbgBufPrint(dbgHdl,"Debugging - %d,%d, %s, %d\n",
  1011.                                 i,cnt++,"Alex Colwell",cnt++);
  1012.                         }
  1013.                         
  1014.                         break;
  1015.                         
  1016.                     case 'c':        /* "Copy" command                */
  1017.                     case 'C':
  1018.                         DoCopy(); c = 0; break;
  1019.                         
  1020.                     case 'k':        /* "Clear" command                */
  1021.                     case 'K':
  1022.                         DoClear(); c = 0;
  1023.                         
  1024.                 }
  1025.                 
  1026.                 if (c) {            /* Check if should continue        */
  1027.                 
  1028.                     if (menu) {        /* Check if got our menu handle    */
  1029.                     
  1030.                                     /* Search for matching item        */
  1031.                         for(i = 1, j = CountMItems(menu); i <= j; i++) {
  1032.                         
  1033.                                     /* Get this item's command        */
  1034.                             GetItemCmd(menu,i,cmdChar);
  1035.                         
  1036.                             if (cmdChar[1] == '?')/* Check if '?' char*/
  1037.                                 cmdChar[1] = '/';/* Translate lower case*/
  1038.                                 
  1039.                                     /* Check if this is it            */
  1040.                             if (!IUMagIDString(&c,&cmdChar[1],1,1)) {
  1041.                                 item = i;/* Yup, save item #        */
  1042.                                 i += j;/* Break-out of loop            */
  1043.                             }
  1044.                             
  1045.                         }
  1046.                         
  1047.                         if (item){    /* Check if got our guy            */
  1048.                         
  1049.                             HiliteMenu(menuID);/* OK, let's highlite it*/
  1050.                             
  1051.                             DoMenu(item);/* Let's do it                */
  1052.                             
  1053.                             HiliteMenu(0);/* Unhighlite the menu    */
  1054.                             
  1055.                         }
  1056.                         
  1057.                         else        /* Opps, wrong menu                */
  1058.                             SysBeep(1);/* Let the user know about it*/
  1059.                         
  1060.                     }
  1061.                     
  1062.                     else            /* Opps, no menu handle            */
  1063.                         SysBeep(1);    /* Let the user know about it    */
  1064.                     
  1065.                 }
  1066.                 
  1067.             }
  1068.             
  1069.             else if (peHdl) {        /* Check if got the text        */
  1070.             
  1071.                 if (sysEnv.keyBoardType == envAExtendKbd || 
  1072.                     sysEnv.keyBoardType == envStandADBKbd) {
  1073.                 
  1074.                                     /* Check if want scroll horz bar*/
  1075.                     if (modifiers & optionKey)
  1076.                         ctrlHdl = hScrollBar;/* Set horz scroll bar    */
  1077.                         
  1078.                     else            /* Nope, use vert scroll bar    */
  1079.                         ctrlHdl = vScrollBar;
  1080.                         
  1081.                     switch(code) {    /* Check if F1-F4 keys            */
  1082.                 
  1083.                            case 0x63:    /* F3 "Copy" key                */
  1084.                             DoCopy(); break;
  1085.                       
  1086.                          case 0x73:    /* Home key                        */
  1087.                          
  1088.                              if (ctrlHdl) {/* Check if has scroll bar*/
  1089.                              
  1090.                                      /* Check if can scroll now        */
  1091.                                  if (i = GetCtlValue(ctrlHdl)) {
  1092.                                  
  1093.                                      /* Reset clippings for scroll bar*/
  1094.                                      ClipRect(&wp->portRect);
  1095.                                      
  1096.                                      /* Reset the current line value    */
  1097.                                      SetCtlValue(ctrlHdl,0);
  1098.                                      
  1099.                                      /* Restore clippings            */
  1100.                                      DoRestoreClippings();
  1101.                                      
  1102.                                      /* OK, let's scroll it now!        */
  1103.                                      if (ctrlHdl == vScrollBar)
  1104.                                            PEScroll(0,(long)(i),peHdl);
  1105.                                        else
  1106.                                            PEScroll(i,0L,peHdl);
  1107.                                      
  1108.                                  }
  1109.                                  
  1110.                              }
  1111.                              
  1112.                              adjustIt = FALSE;/* Don't adjust view    */
  1113.  
  1114.                              break;
  1115.                  
  1116.                          case 0x77:    /* End key                        */
  1117.                          
  1118.                              if (ctrlHdl) {/* Check if has scroll bar*/
  1119.                              
  1120.                                      /* Check if can scroll now        */
  1121.                                  if ((i = GetCtlValue(ctrlHdl)) !=
  1122.                                      (j = GetCtlMax(ctrlHdl))) {
  1123.                                  
  1124.                                      /* Reset clippings for scroll bar*/
  1125.                                      ClipRect(&wp->portRect);
  1126.                                      
  1127.                                      /* Reset the current line value    */
  1128.                                      SetCtlValue(ctrlHdl,j);
  1129.                                      
  1130.                                      /* Restore clippings            */
  1131.                                      DoRestoreClippings();
  1132.                                      
  1133.                                      /* OK, let's scroll it now!        */
  1134.                                      if (ctrlHdl == vScrollBar)
  1135.                                            PEScroll(0,(long)(i - j),peHdl);
  1136.                                        else
  1137.                                            PEScroll(i - j,0L,peHdl);
  1138.                                      
  1139.                                  }
  1140.                                  
  1141.                              }
  1142.                              
  1143.                              adjustIt = FALSE;/* Don't adjust view    */
  1144.  
  1145.                              break;
  1146.                  
  1147.                          case 0x74:    /* Page up key                    */
  1148.                          
  1149.                              if (ctrlHdl) {/* Check if has scroll bar*/
  1150.                              
  1151.                                      /* Scroll text upward            */
  1152.                                  DoTextScroll(ctrlHdl,inPageUp);
  1153.                                  
  1154.                              }
  1155.                              
  1156.                              adjustIt = FALSE;/* Don't adjust view    */
  1157.                              
  1158.                              break;
  1159.                  
  1160.                          case 0x79:    /* Page down key                */
  1161.                          
  1162.                              if (ctrlHdl) {/* Check if has scroll bar*/
  1163.                              
  1164.                                      /* Scroll text downward            */
  1165.                                  DoTextScroll(ctrlHdl,inPageDown);
  1166.                                  
  1167.                              }
  1168.                              
  1169.                              adjustIt = FALSE;/* Don't adjust view    */
  1170.                              
  1171.                              break;
  1172.                  
  1173.                     }
  1174.                 
  1175.                 }
  1176.  
  1177.                 if (adjustIt)        /* Check if should adjust it    */
  1178.                     DoAdjustScrollBar();/* Adjust the scroll bar    */
  1179.                 
  1180.             }
  1181.             
  1182.         }
  1183.         
  1184.     }
  1185.  
  1186. DoMenu(item)
  1187.  
  1188.     short    item;                    /* Item code                    */
  1189.     
  1190.     {
  1191.     
  1192.         switch(item) {                /* Process menu command            */
  1193.         
  1194.             case Info:                /* On-line information            */
  1195.                 DoInfo(); break;
  1196.                 
  1197.             case StartOutput:        /* Start/Stop output display    */
  1198.                 DoStartStopOutput(); break;
  1199.                 
  1200.             case Quit:                /* Quit from the DA                */
  1201.                 DoQuit(); break;
  1202.                 
  1203.         }
  1204.         
  1205.     }
  1206.     
  1207. DoContent(p,modifiers)
  1208.  
  1209.     Point     p;                        /* Mouse down point                */
  1210.     short    modifiers;                /* Mouse's modifiers            */
  1211.     
  1212.     {
  1213.     
  1214.         long            i;            /* Working index                */
  1215.         register short    selectIt = FALSE;/* Working selection flag    */
  1216.         Point            pt;            /* Working point                */
  1217.         
  1218.         pt = p;                        /* Convert to local coordinates    */
  1219.         GlobalToLocal(&pt);
  1220.         
  1221.         if (!DoScrollBar(pt))        /* Check if within scroll bar    */
  1222.             DoTextClick(pt,modifiers);/* Do text clicking            */
  1223.                     
  1224.     }
  1225.     
  1226. DoQuit()
  1227.  
  1228.     {
  1229.     
  1230.         SysBeep(1);                    /* Beep the user now!            */
  1231.         
  1232.         CloseDriver(dce->dCtlRefNum);/* OK, let's close DA            */
  1233.         
  1234.     }
  1235.     
  1236. DoCopy()
  1237.  
  1238.     {
  1239.         
  1240.         register long    len;        /* Working text length            */
  1241.         
  1242.         if (active) {                /* Check if it's activated        */
  1243.         
  1244.             if (peHdl) {            /* Check if have edit handle    */
  1245.                                     /* Check if there any selection    */
  1246.                 if (len = (*peHdl)->selEnd - (*peHdl)->selStart) {
  1247.                 
  1248.                     ZeroScrap();    /* Reset the scrap file            */
  1249.                     
  1250.                     HLock((*peHdl)->hText);/* Lock the text down    */
  1251.                     
  1252.                                     /* Transfer to clipboard        */
  1253.                     PutScrap(len,'TEXT',*(*peHdl)->hText + 
  1254.                              (*peHdl)->selStart);
  1255.                         
  1256.                     HUnlock((*peHdl)->hText);/* OK, safe to unlock it*/
  1257.                     
  1258.                 }
  1259.             
  1260.             }
  1261.             
  1262.         }
  1263.         
  1264.     }
  1265.  
  1266. DoClear()
  1267.  
  1268.     {
  1269.     
  1270.         register Handle    txtHdl;        /* Working text handle            */
  1271.         Rect            wRect;        /* Working rect area            */
  1272.         
  1273.         if (peHdl) {                /* Check if have edit handle    */
  1274.         
  1275.             if (txtHdl = NewHandle(0L)) {/* Check if got new handle    */
  1276.             
  1277.                 ClipRect(&wp->portRect);/* Reset clipping for a moment*/
  1278.                 
  1279.                 if (hScrollBar) {    /* Check if have scroll bar        */
  1280.                     
  1281.                                     /* Reset scroll bar values        */
  1282.                     (*hScrollBar)->contrlMax = 0;
  1283.                     SetCtlValue(hScrollBar,0);
  1284.                     
  1285.                 }
  1286.                 
  1287.                 if (vScrollBar) {    /* Check if have scroll bar        */
  1288.                     
  1289.                                     /* Reset scroll bar values        */
  1290.                     (*vScrollBar)->contrlMax = 0;
  1291.                     SetCtlValue(vScrollBar,0);
  1292.                     
  1293.                 }
  1294.                 
  1295.                 DoRestoreClippings();/* Restore text view clippings    */
  1296.  
  1297.                 DisposHandle((*peHdl)->hText);/* Release old text    */
  1298.                 
  1299.                 (*peHdl)->hText = NIL;/* Reset it to zip!            */
  1300.                 
  1301.                 PESetHText(txtHdl,peHdl);/* Set new text handle        */
  1302.                 
  1303.                 wRect = wp->portRect;/* Clear the display            */
  1304.                 wRect.right -= 15; wRect.bottom -= 15;
  1305.                 InvalRect(&wp->portRect);
  1306.                 
  1307.             }
  1308.             
  1309.         }
  1310.         
  1311.     }
  1312.  
  1313. DoInfo()
  1314.  
  1315.     {
  1316.     
  1317.         register DialogPtr    dPtr;    /* Working dialog pointer        */
  1318.         short                dItem;    /* Working dialogue item        */
  1319.         register short        next = TRUE;/* Working next event flag    */
  1320.         
  1321.         if (dbgHdl) {                /* Check if got debugger ref hdl*/
  1322.         
  1323.             (*dbgHdl)->daRefNbr = 0;/* Clear debugger ref handle    */
  1324.             ChangedResource(dbgHdl);
  1325.             WriteResource(dbgHdl);
  1326.         
  1327.         }
  1328.         
  1329.         DoDeActivateScrollBars();    /* Deactivate the scroll bars    */
  1330.         
  1331.         DoDlgCenter('DLOG',infoID);    /* Center the dialog now        */
  1332.         
  1333.                                     /* Check if open dialog            */
  1334.         if (dPtr =  GetNewDialog(GetResourceID(infoID),NIL,-1L)) {
  1335.         
  1336.             InitCursor();            /* Restore to arrow cursor        */
  1337.             
  1338.             cursorMode = FALSE;        /* Reset cursor mode            */
  1339.             
  1340.             SetPort(dPtr);            /* Set to my window port        */
  1341.             
  1342.             while(next) {            /* Process next event            */
  1343.             
  1344.                 ModalDialog(NIL,&dItem);/* Get modal event            */
  1345.                      
  1346.                 if (dItem == OK)    /* Check if time to quit        */
  1347.                     next = FALSE;    /* Let's break-out !            */
  1348.                     
  1349.             }
  1350.             
  1351.             SetPort(wp);            /* Restore DA's window port        */
  1352.             
  1353.              DisposDialog(dPtr);        /* Kill dialogue window            */
  1354.                       
  1355.         }
  1356.         
  1357.         DoActivateScrollBars();        /* Activate the scroll bars        */
  1358.         
  1359.         if (dbgHdl) {                /* Check if got debugger ref hdl*/
  1360.         
  1361.             if (outputEnable) {        /* Check if display is enabled    */
  1362.             
  1363.                                     /* Restore debugger ref handle    */
  1364.                 (*dbgHdl)->daRefNbr = dce->dCtlRefNum;
  1365.                 ChangedResource(dbgHdl);
  1366.                 WriteResource(dbgHdl);
  1367.             
  1368.             }
  1369.             
  1370.         }
  1371.         
  1372.     }
  1373.  
  1374. DoStartStopOutput()
  1375.  
  1376.     {
  1377.     
  1378.         Str255        wStr;            /* Working item string            */
  1379.         
  1380.         if (dbgHdl) {                /* Check if has debugger resource*/
  1381.         
  1382.             if (outputEnable) {        /* Check if want to turn it off*/
  1383.             
  1384.                 outputEnable = FALSE;/* Disable output display        */
  1385.                 
  1386.                 (*dbgHdl)->daRefNbr = 0;/* Disable output processing*/
  1387.                 
  1388.                                     /* Get item string to reset        */
  1389.                 GetIndString(wStr,GetResourceID(strID),itmStartOutput);
  1390.                 
  1391.             }
  1392.             
  1393.             else {                    /* Nope, start-up output processing*/
  1394.             
  1395.                 outputEnable = TRUE;/* Enable output display        */
  1396.                 
  1397.                                     /* Enable output processing        */
  1398.                 (*dbgHdl)->daRefNbr = dce->dCtlRefNum;
  1399.     
  1400.                                     /* Get item string to reset        */
  1401.                 GetIndString(wStr,GetResourceID(strID),itmStopOutput);
  1402.                 
  1403.             }
  1404.             
  1405.             SetItem(menu,StartOutput,wStr);/* Reset the item string    */
  1406.         
  1407.         }
  1408.         
  1409.     }
  1410.  
  1411. DoError(errMsg)
  1412.  
  1413.     ERROR    errMsg;                    /* Error message                */
  1414.     
  1415.     {
  1416.     
  1417.         Str255    wStr;                /* Working string                */
  1418.         
  1419.         if (dbgHdl) {                /* Check if got debugger ref hdl*/
  1420.         
  1421.             (*dbgHdl)->daRefNbr = 0;/* Clear debugger ref handle    */
  1422.             ChangedResource(dbgHdl);
  1423.             WriteResource(dbgHdl);
  1424.         
  1425.         }
  1426.         
  1427.                                     /* Get error message            */
  1428.         GetIndString(wStr,GetResourceID(errID),errMsg);
  1429.         
  1430.         ParamText(wStr,"","","");    /* Setup parameter text messages*/
  1431.         
  1432.         DoDlgCenter('ALRT',errorID);/* Center the alert dialog        */
  1433.         
  1434.         DoDeActivateScrollBars();    /* Deactivate the scroll bars    */
  1435.         
  1436.         CautionAlert(GetResourceID(errorID),NIL);/* Inform user now    */
  1437.         
  1438.         DoActivateScrollBars();        /* Activate the scroll bars        */
  1439.         
  1440.         if (dbgHdl) {                /* Check if got debugger ref hdl*/
  1441.         
  1442.             if (outputEnable) {        /* Check if display is enabled    */
  1443.             
  1444.                                     /* Restore debugger ref handle    */
  1445.                 (*dbgHdl)->daRefNbr = dce->dCtlRefNum;
  1446.                 ChangedResource(dbgHdl);
  1447.                 WriteResource(dbgHdl);
  1448.             
  1449.             }
  1450.             
  1451.         }
  1452.         
  1453.     }
  1454.  
  1455. DoTextClick(pt,modifiers)
  1456.  
  1457.     Point    pt;                        /* Mouse down point                */
  1458.     short    modifiers;                /* Modifiers selection            */
  1459.     
  1460.     {
  1461.     
  1462.         register short    extendIt = FALSE;/* Working extend selection*/
  1463.  
  1464.         if (peHdl) {                /* Check if got the text        */
  1465.         
  1466.             if ((*peHdl)->peLength > 0) {/* Check if there any text    */
  1467.             
  1468.                 if (modifiers & shiftKey)/* Check if want to extend it*/
  1469.                     extendIt = TRUE;/* Extend the selection then    */
  1470.             
  1471.                 PEClick(pt,extendIt,peHdl);/* Do clicking stuff        */
  1472.             
  1473.             }
  1474.         
  1475.         }
  1476.         
  1477.     }
  1478.  
  1479. DoScrollBar(pt)
  1480.  
  1481.     Point    pt;                        /* Mouse down point                */
  1482.     
  1483.     {
  1484.     
  1485.         register short    partCtrl;    /* Working control part            */
  1486.         ControlHandle    ctrlHdl;    /* Working control handle        */
  1487.  
  1488.                                     /* Check if got a control part    */
  1489.         if (partCtrl = FindControl(pt,wp,&ctrlHdl)) {
  1490.         
  1491.             ClipRect(&wp->portRect);/* Set clippings for scrolling    */
  1492.             
  1493.             if (partCtrl == inThumb) {/* Check if using thumb        */
  1494.             
  1495.                                     /* Save current control's value    */
  1496.                 SetCRefCon(ctrlHdl,GetCtlValue(ctrlHdl));
  1497.                 
  1498.                    ClipRect(&wp->portRect);/* Reset clippings for a moment*/
  1499.        
  1500.                 TrackControl(ctrlHdl,pt,NIL);/* Let's track by thumb*/
  1501.                 
  1502.                 DoTextScroll(ctrlHdl,inThumb);/* OK, let's scroll    */
  1503.                 
  1504.                 DoRestoreClippings();/* Restore text view clippings    */
  1505.             
  1506.             }
  1507.             
  1508.             else {                    /* Nope, other types of scrolling*/
  1509.             
  1510.                    ClipRect(&wp->portRect);/* Reset clippings for a moment*/
  1511.        
  1512.                                     /* OK, lets scroll it now        */
  1513.                 TrackControl(ctrlHdl,pt,DoTextScroll);
  1514.                 
  1515.                 DoRestoreClippings();/* Restore text view clippings    */
  1516.             
  1517.             }
  1518.             
  1519.         }
  1520.  
  1521.         return(partCtrl);            /* Return part control            */
  1522.         
  1523.     }
  1524.  
  1525. pascal void DoTextScroll(ctrlHdl,partCtrl)
  1526.  
  1527.     ControlHandle    ctrlHdl;        /* Control scroll handle        */
  1528.     short            partCtrl;        /* Control's part                */
  1529.     
  1530.     {
  1531.     
  1532.         register short    delta;        /* Working delta scroll            */
  1533.         register short    value;        /* Working current value        */
  1534.         register short    maxValue;    /* Working maximum value        */
  1535.         register short    viewLines;    /* Working view lines            */
  1536.         short            dh = 0;        /* Working delta horizonal        */
  1537.         long            dv = 0;        /* Working delta vertical        */
  1538.         PEPtr            pePtr;        /* Working edit pointer            */
  1539.         
  1540.         SetUpA4();                    /* Setup register A4            */
  1541.         
  1542.         delta = GetCtlValue(ctrlHdl);/* Get current value            */
  1543.         
  1544.         maxValue = GetCtlMax(ctrlHdl);/* Get maximum value            */
  1545.         
  1546.         switch(partCtrl) {            /* Handle request:                */
  1547.     
  1548.             case 0:                    /*        "Nothing"                */
  1549.                  return;
  1550.          
  1551.           case inUpButton:
  1552.                 
  1553.              value = max(0,delta - 1);/* Set new value position        */
  1554.             
  1555.              break;
  1556.                     
  1557.           case inDownButton:
  1558.                 
  1559.              value = min(maxValue,delta + 1);/* Set new value position*/
  1560.             
  1561.              break;
  1562.  
  1563.             case inPageUp:            /*        "Page Up"                */
  1564.             case inPageDown:        /*         "Page Down"                */
  1565.  
  1566.                 if (ctrlHdl == vScrollBar) {/* Check if vertical    */
  1567.                 
  1568.                    pePtr = *peHdl;    /* Set edit text pointer        */
  1569.     
  1570.                                     /* Set # of visible lines by half*/
  1571.                    viewLines = (pePtr->viewRect.bottom - 
  1572.                                   pePtr->viewRect.top) / pePtr->lineHeight;
  1573.                 
  1574.                    if (partCtrl == inPageUp)/* Check if page up region    */
  1575.                       value = max(0,delta - viewLines);
  1576.                 
  1577.                    else             /* Nope, page down region        */
  1578.                       value = min(maxValue,delta + viewLines);
  1579.                 
  1580.                 }
  1581.                 
  1582.                 else {                /* Check if horizontal            */
  1583.                 
  1584.                    if (partCtrl == inPageUp)/* Check if page up region*/
  1585.                       value = max(0,delta - 10);/* Set new position */
  1586.             
  1587.                    else             /* Nope, page down region        */
  1588.                       value = min(maxValue,delta + 10);
  1589.             
  1590.                 }
  1591.                 
  1592.                 break;
  1593.                 
  1594.             case inThumb:            /*        "Thumb"                    */
  1595.             
  1596.                 delta = GetCRefCon(ctrlHdl);/* Get starting value    */
  1597.                 
  1598.                  value = GetCtlValue(ctrlHdl);/* Get new value position*/
  1599.                 
  1600.         }
  1601.     
  1602.        SetCtlValue(ctrlHdl,value);     /* Reset the value                */
  1603.     
  1604.        if (hScrollBar == ctrlHdl)    /* Check if horzontal            */
  1605.           dh = delta - value;        /* Set horizontal offset        */
  1606.         
  1607.        else
  1608.           dv = delta - value;        /* Set vertical offset            */
  1609.             
  1610.        DoRestoreClippings();        /* Restore text view clippings    */
  1611.             
  1612.        if (dh || dv)                /* Check if should scroll it    */
  1613.           PEScroll(dh * CharWidth(' '),dv,peHdl);/* Scroll it now    */
  1614.     
  1615.        ClipRect(&wp->portRect);        /* Reset clippings for a moment    */
  1616.        
  1617.        RestoreA4();                    /* Restore register A4            */
  1618.         
  1619.     }
  1620.  
  1621. pascal void DoClickScroll(peHdl)
  1622.  
  1623.    register PEHandle    peHdl;        /* Edit data handle             */
  1624.  
  1625.    {
  1626.  
  1627.       register Rect     viewRect;    /* Working view rect area        */
  1628.       Point             pt;         /* Working mouse point position */
  1629.     
  1630.       viewRect = (*peHdl)->viewRect;/* Set view rect area            */
  1631.     
  1632.       GetMouse(&pt);                /* Get current mouse position    */
  1633.     
  1634.       if (pt.v < viewRect.top)         /* Check if going upward        */
  1635.          DoTextScroll(vScrollBar,inUpButton);
  1636.     
  1637.       else if (pt.v > viewRect.bottom)/* Check if going downward    */
  1638.          DoTextScroll(vScrollBar,inDownButton);
  1639.     
  1640.       else if (pt.h < viewRect.left)/* Check if going leftward        */
  1641.          DoTextScroll(hScrollBar,inUpButton);
  1642.     
  1643.       else if (pt.h > viewRect.right)/* Check if going rightward     */
  1644.          DoTextScroll(hScrollBar,inDownButton);
  1645.     
  1646.    }
  1647.    
  1648. pascal    void    DoHighLite(hilite,pePtr)
  1649.  
  1650.   Rect        *hilite;                /* Highlite rect area            */
  1651.   register PEPtr pePtr;                /* Edit text pointer            */
  1652.   
  1653.   {
  1654.   
  1655.      HiliteMode &= 0x7f;            /* Set highliting bit            */
  1656.      
  1657.      InvertRect(hilite);            /* Invert rect area                */
  1658.      
  1659.   }
  1660.  
  1661. DoNewLineToReturn(s)
  1662.  
  1663.     char    *s;                        /* Input string pointer            */
  1664.  
  1665.     {
  1666.         while(*s) {                    /* Convert NEW-LINEs to RETURNs    */
  1667.             if (*s == '\n')            /* Check if this is NEW-LINE char*/
  1668.                 *s = '\r';            /* Convert to RETURN character    */
  1669.             s += 1;                    /* Bump to next character        */
  1670.         }
  1671.     }
  1672.     
  1673. DoPrintLine(format,args)
  1674.  
  1675.     char    *format;                /* Format string pointer        */
  1676.     va_list    args;                    /* Argument's list                */
  1677.  
  1678.     {
  1679.     
  1680.         vsprintf(PrintOutputBuf,format,&args);/* Format str to buf    */
  1681.         
  1682.         DoNewLineToReturn(PrintOutputBuf);/* Convert NEW-LINE to RETURN*/
  1683.         
  1684.                                     /* Output string to display        */
  1685.         PEInsert(PrintOutputBuf,DbgStrLen(PrintOutputBuf),peHdl);
  1686.         
  1687.         DoAdjustScrollBar();        /* Adjust the scroll bar        */
  1688.         
  1689.     }
  1690.     
  1691. DoDbgPrintSetUp(fmt)
  1692.  
  1693.     char        *fmt;                /* Input format pointer            */
  1694.     
  1695.     {
  1696.     
  1697.                     
  1698.         register short    fLen;        /* Working format string length    */
  1699.         register char    *stack;        /* Working fake stack pointer    */
  1700.         
  1701.         fLen = DbgStrLen(fmt) + 1;    /* Set string length            */
  1702.         
  1703.         if (fLen & 0x1)                /* Check if it's even # of chars*/
  1704.             fLen += 1;                /* Align it to even addresss    */
  1705.             
  1706.         stack = fmt + fLen;            /* Set format string address    */
  1707.         *((long *)(stack)) = ((long)(fmt));
  1708.                 
  1709.         DoDbgPrint(stack);            /* OK, let's really do it        */
  1710.         
  1711.     }
  1712.  
  1713. DoDbgPrint(args)
  1714.  
  1715.     long    *args;                    /* Input argument's list        */
  1716.     
  1717.     {
  1718.     
  1719.           DoSetupView();                /* Setup the view display        */
  1720.       
  1721.         DoAdjustView();                /* Adjust the view                */
  1722.           
  1723.         vsprintf(PrintOutputBuf,*args,args + 1L);/* Format str to buffer*/
  1724.         
  1725.         DoNewLineToReturn(PrintOutputBuf);/* Convert NEW-LINE to RETURN*/
  1726.         
  1727.                                     /* Output string to display        */
  1728.         PEInsert(PrintOutputBuf,DbgStrLen(PrintOutputBuf),peHdl);
  1729.         
  1730.         DoAdjustScrollBar();        /* Adjust the scroll bar        */
  1731.         
  1732.     }
  1733.     
  1734. DoPrintDump(ptr,size)
  1735.  
  1736.     char    *ptr;                    /* Print buffer pointer            */
  1737.     long    size;                    /* Print buffer length            */
  1738.     
  1739.     {
  1740.     
  1741.       register    long    i,j,k,m,n;    /* Working indexes                */
  1742.       register    char    *tptr;        /* Working temporary pointer    */
  1743.       Str255            buffer;        /* Working string buffer        */
  1744.       Str255            tbuffer;    /* Working temporary buffer        */
  1745.       
  1746.       DoSetupView();                /* Setup the view display        */
  1747.       
  1748.       DoAdjustView();                /* Adjust the view                */
  1749.       
  1750.                                       /* Output # of bytes dumped        */
  1751.       DoPrintLine("\nNumber of bytes - %ld\n",size);
  1752.       DoPrintLine("Cnt  Address  %s %s\n",
  1753.                     "Hex Values—————————————————————————",
  1754.                     "ASCII Values————");
  1755.  
  1756.       for(i = 0L; i < size; i += 16L) {/* Transfer all the data        */
  1757.       
  1758.          n = 14L;                    /* Set init buffer index        */
  1759.          
  1760.          for(j = 0L; j < sizeof(buffer); j++)/* Clear buffer string    */
  1761.             buffer[j] = ' ';        /* Pad it with spaces            */
  1762.          
  1763.          sprintf(buffer,"%04ld %08lx ",i,tptr = ptr);/* Set init hdr*/
  1764.          
  1765.          j = i; k = m = 0L;            /* Init indexes                    */
  1766.          
  1767.          while(j < size && m < 16L) {/* Output hex parts            */
  1768.             
  1769.             m += 1L;                /* Bump # of characters            */
  1770.             
  1771.             if (k++ == 3L) {        /* Check if time to pad space    */
  1772.             
  1773.                sprintf(tbuffer,"%04x ",*tptr++);/* Get char hex value*/
  1774.                
  1775.                                        /* Add it to output buffer        */
  1776.                BlockMove(&tbuffer[2],&buffer[n],
  1777.                        DbgStrLen((char *)(&tbuffer[2])) + 1);
  1778.                
  1779.                k = 0L;                /* Reset index                    */
  1780.                
  1781.                n += 1L;                /* Bump one extra                */
  1782.  
  1783.             }
  1784.             
  1785.             else {
  1786.             
  1787.                sprintf(tbuffer,"%04x",*tptr++);/* Get char hex value*/
  1788.           
  1789.                                        /* Add it to output buffer        */
  1790.                BlockMove(&tbuffer[2],&buffer[n],
  1791.                        DbgStrLen((char *)(&tbuffer[2])) + 1);
  1792.                
  1793.             }
  1794.             
  1795.             j += 1L;                /* Bump to next character        */
  1796.             
  1797.             n += 2L;                /* Bump for two hex characters    */
  1798.             
  1799.          }
  1800.            
  1801.          buffer[n] = ' ';            /* Remove the end-of-string        */
  1802.          
  1803.          n = 50L;                    /* Reset the character index    */
  1804.          
  1805.          j = i; m = 0L;                /* Init indexes                    */
  1806.          
  1807.          while(j < size && m < 16L) {/* Output hex parts            */
  1808.             
  1809.             j += 1L;                /* Bump to next character        */
  1810.             
  1811.             m += 1L;                /* Bump # of characters            */
  1812.             
  1813.             if (isprint(*ptr))        /* Check if printable            */
  1814.                sprintf(&buffer[n],"%c",*ptr++);/* Output char        */
  1815.         
  1816.             else {                    /* It's not printable            */
  1817.         
  1818.                   BlockMove(".",&buffer[n],2L);/* Show period only        */
  1819.                   
  1820.                ptr += 1L;            /* Bump to next character        */
  1821.            
  1822.             }
  1823.         
  1824.             n += 1L;                /* Bump for one character        */
  1825.             
  1826.          }
  1827.            
  1828.                                      /* Add RETURN character            */
  1829.          BlockMove("\r",&buffer[DbgStrLen((char *)(buffer))],2L);
  1830.          
  1831.          DoPrintLine("%s",buffer);    /* Output the string            */
  1832.          
  1833.       }
  1834.       
  1835.     }
  1836.     
  1837. DoRestoreClippings()
  1838.  
  1839.     {
  1840.     
  1841.         Rect    wRect;                /* Working rect area            */
  1842.         
  1843.           if (peHdl) {                /* Check if it's valid            */
  1844.  
  1845.             wRect = (*peHdl)->viewRect;/* Restore clipping            */
  1846.             ClipRect(&wRect);
  1847.         
  1848.         }
  1849.         
  1850.     }
  1851.     
  1852. DoAdjustScrollBar()
  1853.  
  1854.     {
  1855.     
  1856.         register short    viewHeight;    /* Working view height            */
  1857.         register short    hiddenLines;/* Working # of hidden lines    */
  1858.         register PEPtr    pePtr;        /* Working edit pointer            */
  1859.         
  1860.         if (peHdl) {                /* Check if have edit handle    */
  1861.         
  1862.             pePtr = *peHdl;            /* Set edit pointer                */
  1863.             
  1864.             if (pePtr->peLength) {    /* Check if there any text        */
  1865.             
  1866.                 ClipRect(&wp->portRect);/* Reset clippings for moment*/
  1867.                 
  1868.                 if (hScrollBar) {    /* Check if there a horz scroll    */
  1869.                 
  1870.                     if (!GetCtlMax(hScrollBar))/* Check if not init    */
  1871.                         SetCtlMax(hScrollBar,maxColumns);/* Reset to max*/
  1872.                         
  1873.                 }
  1874.                 
  1875.                 if (vScrollBar) {    /* Check if there a vert scroll    */
  1876.                 
  1877.                                     /* Set view height display        */
  1878.                     viewHeight = abs(pePtr->viewRect.bottom - 
  1879.                                      pePtr->viewRect.top);
  1880.                                      
  1881.                                      /* Check if need to enable it    */
  1882.                     if (pePtr->nLines * pePtr->lineHeight > viewHeight) {
  1883.                     
  1884.                                     /* Set # of hidden lines        */
  1885.                         hiddenLines = max(0,pePtr->nLines - viewHeight / 
  1886.                                               pePtr->lineHeight);
  1887.                                       
  1888.                                       /* Check if the hidden lines changed*/
  1889.                         if (GetCtlMax(vScrollBar) != hiddenLines) {
  1890.                         
  1891.                                     /* Update the maximum # of lines*/
  1892.                             (*vScrollBar)->contrlMax = hiddenLines - 1;
  1893.                             
  1894.                                     /* Adjust thumb position        */
  1895.                                SetCtlValue(vScrollBar,
  1896.                                    min((short)pePtr->viewOrgV,hiddenLines - 1));
  1897.                                    
  1898.                             DoAdjustView();/* Adjust the view        */
  1899.                             
  1900.                         }
  1901.                         
  1902.                     }
  1903.                     
  1904.                     else {            /* Nope, disable the scroll bar    */
  1905.                     
  1906.                                     /* Check if it's enabled        */
  1907.                         if (GetCtlMax(vScrollBar)) {
  1908.                         
  1909.                             (*vScrollBar)->contrlMax = 0;/* Reset it*/
  1910.                             SetCtlValue(vScrollBar,0);
  1911.                         
  1912.                         }
  1913.                     
  1914.                     }
  1915.                         
  1916.                 }
  1917.                 
  1918.             }
  1919.             
  1920.             else {                    /* Reset the scroll bars        */
  1921.             
  1922.                 if (hScrollBar) {    /* Check if there a horz scroll    */
  1923.                 
  1924.                     if (GetCtlMax(hScrollBar)) {/* Check if enabled    */
  1925.                     
  1926.                         (*hScrollBar)->contrlMax = 0;/* Reset it    */
  1927.                         SetCtlValue(hScrollBar,0);
  1928.                     
  1929.                     }
  1930.                 
  1931.                 }
  1932.                 
  1933.                 if (vScrollBar) {    /* Check if there a vert scroll    */
  1934.                 
  1935.                     if (GetCtlMax(vScrollBar)) {/* Check if enabled    */
  1936.                     
  1937.                         (*vScrollBar)->contrlMax = 0;/* Reset it    */
  1938.                         SetCtlValue(vScrollBar,0);
  1939.                     
  1940.                     }
  1941.                 
  1942.                 }
  1943.                 
  1944.             }
  1945.             
  1946.             DoRestoreClippings();    /* Restore text view clippings    */
  1947.         
  1948.         }
  1949.                 
  1950.     }
  1951.     
  1952. DoSetupView()
  1953.  
  1954.     {
  1955.     
  1956.         register PEPtr     pePtr;        /* Working edit data pointer    */
  1957.     
  1958.         if (peHdl) {                /* Check if have edit handle    */
  1959.         
  1960.             pePtr = *peHdl;            /* Set edit pointer                */
  1961.             
  1962.                                     /* Check if have selected text    */
  1963.             if (pePtr->selStart != pePtr->selEnd)
  1964.                 PESetSelect(pePtr->peLength,pePtr->peLength,peHdl);
  1965.                 
  1966.                                     /* Check if not at end-of-text    */
  1967.             else if (pePtr->selStart != pePtr->peLength)
  1968.                 PESetSelect(pePtr->peLength,pePtr->peLength,peHdl);
  1969.                 
  1970.         }
  1971.         
  1972.     }
  1973.     
  1974. DoAdjustView()
  1975.  
  1976.   {
  1977.  
  1978.      register PEPtr     pePtr;        /* Working edit data pointer    */
  1979.      long                delta;        /* Working delta line offset    */
  1980.      long                currentLine;/* Working current line selection*/
  1981.      register long        selectLine;/* Working line selection        */
  1982.      register long        viewLines;    /* Working view lines            */
  1983.      long                hViewLines; /* Working half view lines        */
  1984.      register long        viewOrgV;    /* Working origin view offset    */
  1985.      long                saveSelStr; /* Working save selStart value    */
  1986.      long                saveSelEnd; /* Working save selEnd value    */
  1987.      register long        status = TRUE;/* Working adjust view indicator*/
  1988.      short                adjust = FALSE;/* Working vertical adjustment*/
  1989.     
  1990.      if (peHdl) {                    /* Check if have edit handle    */
  1991.      
  1992.          DoRestoreClippings();        /* Restore text view clippings    */
  1993.                     
  1994.          pePtr = *peHdl;            /* Set edit text pointer        */
  1995.                 
  1996.          if (optHdl) {                /* Check if option handle valid    */
  1997.          
  1998.              if ((*optHdl)->maxTextSize) {/* Check if maxing input data*/
  1999.                 
  2000.                                     /* Set current line to chop     */
  2001.                 currentLine = pePtr->peLength - (*optHdl)->maxTextSize;
  2002.                 
  2003.                 if (currentLine > 0) {/* Check if time to chop        */
  2004.                 
  2005.                    PECloseGap(peHdl);/* Close the gap first            */
  2006.                 
  2007.                    saveSelStr = pePtr->selStart;/* Save start selection*/
  2008.                 
  2009.                    saveSelEnd = pePtr->selEnd;/* Save end selection    */
  2010.                 
  2011.                                     /* Reset selection                */
  2012.                    PESetSelect(0L,currentLine = PEEol(currentLine,
  2013.                                   peHdl) + 1L,peHdl);
  2014.                 
  2015.                    PEDelete(peHdl);    /* OK, let's delete it          */
  2016.                 
  2017.                                     /* Restore it                    */
  2018.                    PESetSelect(saveSelStr - currentLine,
  2019.                                   saveSelEnd - currentLine,peHdl);
  2020.                 
  2021.                 }
  2022.                 
  2023.              }
  2024.         
  2025.          }
  2026.          
  2027.          pePtr = *peHdl;            /* Set edit text pointer        */
  2028.         
  2029.          viewOrgV = pePtr->viewOrgV;/* Set view origin offset        */
  2030.         
  2031.                                     /* Set # of visible lines        */
  2032.          viewLines = abs(pePtr->viewRect.bottom - pePtr->viewRect.top) /
  2033.                       pePtr->lineHeight;
  2034.         
  2035.          hViewLines = viewLines / 2;/* Half of the view lines        */
  2036.         
  2037.                                     /* Set selected line #            */
  2038.          selectLine = currentLine = PELineNum(pePtr->selEnd,peHdl);
  2039.         
  2040.          pePtr = *peHdl;            /* Reset edit text pointer        */
  2041.         
  2042.                                     /* Check if within view         */
  2043.          if (selectLine >= viewOrgV && selectLine < viewOrgV + viewLines)
  2044.             status = FALSE;
  2045.             
  2046.          if (status) {                /* Check if should adjust view    */
  2047.         
  2048.             adjust = TRUE;            /* Set adjust the vertical offset*/
  2049.             
  2050.             selectLine -= viewOrgV; /* Adjust select line #         */
  2051.             
  2052.             if (selectLine == viewLines)/* Check if just off the page*/
  2053.                selectLine -= viewLines - 1;/* Adjust by one line    */
  2054.             
  2055.                                     /* Check if close to the bottom */
  2056.             else if (delta = (pePtr->nLines - currentLine - 
  2057.                               1 - hViewLines) < 0)
  2058.                selectLine += delta - viewLines;/* Adjust to bottom of file*/
  2059.             
  2060.             else if (selectLine != -1)    /* Check if completely off    */
  2061.                selectLine -= hViewLines;/* Center the page            */
  2062.             
  2063.             selectLine += viewOrgV; /* Adjust to physical offset    */
  2064.             
  2065.                                     /* Scroll to cursor             */
  2066.             PEScrollTo(pePtr->viewOrgH,selectLine,peHdl);
  2067.             
  2068.          }
  2069.      
  2070.      }
  2071.     
  2072.   }
  2073.  
  2074. DoResizeScrollBar()
  2075.  
  2076.     {
  2077.     
  2078.         Rect    wRect;                /* Working window rect area        */
  2079.         
  2080.         if (peHdl) {                /* Check if have edit handle    */
  2081.         
  2082.             wRect.left = wp->portRect.left;
  2083.             wRect.top = wp->portRect.top + 5;
  2084.             wRect.right = wp->portRect.right - 15;
  2085.             wRect.bottom = wp->portRect.bottom - 15;
  2086.  
  2087.             (*peHdl)->viewRect = wRect;
  2088.             
  2089.         }
  2090.         
  2091.         if (hScrollBar) {            /* Check if have scroll bar        */
  2092.         
  2093.                                     /* Compute scroll bar rect area    */
  2094.             wRect.left = wp->portRect.left - 1;
  2095.             wRect.top = wp->portRect.bottom - 15;
  2096.             wRect.right = wp->portRect.right - 14;
  2097.             wRect.bottom = wp->portRect.bottom + 1;
  2098.       
  2099.                                       /* Set new control rect area    */
  2100.             (*hScrollBar)->contrlRect = wRect;
  2101.      
  2102.          }
  2103.          
  2104.         if (vScrollBar) {            /* Check if have scroll bar        */
  2105.         
  2106.                                     /* Compute scroll bar rect area    */
  2107.             wRect.left = wp->portRect.right - 15;
  2108.             wRect.top = wp->portRect.top - 1;
  2109.             wRect.right = wp->portRect.right + 1;
  2110.             wRect.bottom = wp->portRect.bottom - 14;
  2111.       
  2112.                                       /* Set new control rect area    */
  2113.             (*vScrollBar)->contrlRect = wRect;
  2114.      
  2115.          }
  2116.          
  2117.     }
  2118.     
  2119. DialogTHndl DoDlgCenter(type,id)
  2120.  
  2121.    long     type;                        /* Resource type id                */
  2122.    short id;                        /* Id #                            */
  2123.    
  2124.    {
  2125.    
  2126.       register DialogTHndl dhdl;    /* Working dialog template handle*/
  2127.       register DialogTPtr  dptr;    /* Working dialog template pointer*/
  2128.       WindowPtr              wPtr;    /* Working window pointer        */
  2129.       register short       swidth;    /* Working 1/2 horz screen width*/
  2130.       register short       width;    /* Working 1/2 horz dialog width*/
  2131.       
  2132.                                       /* Check if got the dialog handle*/
  2133.       if (dhdl = ((DialogTHndl)GetResource(type,GetResourceID(id)))) {    
  2134.       
  2135.            GetWMgrPort(&wPtr);        /* Get window manager pointer    */
  2136.            
  2137.          dptr = *dhdl;                /* Set dialog template pointer    */
  2138.          
  2139.                                      /* Set 1/2 screen width            */
  2140.          swidth = abs(wPtr->portRect.right - wPtr->portRect.left) / 2;
  2141.          
  2142.                                      /* Set 1/2 dialog width            */
  2143.          width = abs(dptr->boundsRect.right - dptr->boundsRect.left) / 2;
  2144.          
  2145.                                      /* Center the dialog            */
  2146.          dptr->boundsRect.left = swidth - width;
  2147.          dptr->boundsRect.right = swidth + width;
  2148.          
  2149.       }
  2150.       
  2151.       return(dhdl);                    /* Return dialog handle            */
  2152.       
  2153.    }
  2154.  
  2155. DoItemIdx(item,menu)
  2156.  
  2157.     register unsigned char    *item;    /* Item string to look up        */
  2158.     register MenuHandle        menu;    /* Menu handle                    */
  2159.     
  2160.     {
  2161.     
  2162.         register short    i,j;        /* Working index                */
  2163.         register unsigned short    len = *item++;/* Working item length*/
  2164.         Str255            wStr;        /* Working string                */
  2165.         
  2166.                                     /* Look for matching item        */
  2167.         for(i = 1, j = CountMItems(menu); i <= j; i++) {
  2168.         
  2169.             GetItem(menu,i,&wStr);    /* Working string                */
  2170.             
  2171.             if (!IUMagString(item,&wStr[1],len,len))/* Check if matches*/
  2172.                 return(i);            /* Found matching string        */
  2173.                 
  2174.         }
  2175.         
  2176.         return(1);                    /* Opps, didn't find it            */
  2177.         
  2178.     }
  2179.  
  2180. GetResourceID(n) { return(0xC000 + ((~(dce->dCtlRefNum))<<5) + n); }
  2181.  
  2182.